package com.hanhanxiaochong.zhongxiangchuanmei.presenter;

import com.hanhanxiaochong.zhongxiangchuanmei.bean.GoodDetailBean;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.ShoppingCartBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.HttpPostService;
import com.hanhanxiaochong.zhongxiangchuanmei.presenter.base.BasePresenter;
import com.hanhanxiaochong.zhongxiangchuanmei.util.ToastUtils;
import com.hanhanxiaochong.zhongxiangchuanmei.view.iview.IGoodDetailView;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseApi;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseObserver;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.ResponseBase;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by RockPhoenix on 2018/5/25.
 */

public class GoodDetailPresenter extends BasePresenter<IGoodDetailView> {

    public GoodDetailPresenter(IGoodDetailView iView) {
        super(iView);
    }

    @Override
    public void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi) {

    }

    @Override
    public void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi, int state) {

    }

    public void getGoodDetailInfo(String good_id) {
        RetrofitSource.createApi(HttpPostService.class).goods_detail(good_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<GoodDetailBean>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<GoodDetailBean> response) {
                        iView.setGoodInfo(response.getData());
                    }
                });
    }

    public void addShoppingCart(String token, String good_id, String good_num, String store_id) {
        RetrofitSource.createApi(HttpPostService.class).shop_cart(token, good_id, good_num, store_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<List<ShoppingCartBean>>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<List<ShoppingCartBean>> response) {
                        ToastUtils.showToast("添加购物车成功");
                    }
                });
    }
}
